feat: add configurable request timeout to the Creators API - #151
Open
YPCrumble wants to merge 1 commit into
Open
feat: add configurable request timeout to the Creators API#151YPCrumble wants to merge 1 commit into
YPCrumble wants to merge 1 commit into
Conversation
The sync AmazonCreatorsApi called the bundled SDK without _request_timeout, so urllib3 received an explicit None and requests could hang forever. The async layer already applied a 30 second timeout, but did not let callers change it. Both classes now accept a timeout parameter in seconds, sharing the existing DEFAULT_TIMEOUT of 30 seconds. That constant moves to core.constants so the sync layer can use it without pulling in the optional httpx dependency, and is re-exported from aio.client for compatibility. Passing None restores the previous behavior of waiting indefinitely. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The sync
AmazonCreatorsApicallsself._api.<method>(...)without_request_timeoutat all four call sites (get_items,search_items,get_variations,get_browse_nodes). The bundled SDK'srest.pythen takes itstimeout = Nonebranch and hands that explicitNoneto urllib3, so no timeout is applied at all and a stalled endpoint hangs the caller indefinitely.The async layer already gets this right:
aio/client.pydefinesDEFAULT_TIMEOUT = 30.0and passes it to httpx. Same library, opposite safety default — and neither one is configurable today.This adds a
timeoutparameter, in seconds, to both classes, and reuses the existing 30 second default for the sync layer rather than introducing a new number.Behavior change
Sync requests now time out after 30 seconds instead of waiting forever. That is a real change, and it is the point of the PR — but it is a change, so
timeout=Noneis supported and restores the old behavior exactly, for anyone who wants it.I went with a real default rather than an opt-in
Nonebecause "no timeout" is not a defensible default for a network client, and because 30 seconds is not a new opinion — it is the value this library already ships and has been using in the async layer since 6.1.0. If you would rather keep this strictly non-breaking, I am happy to flip the sync default toNone(opt-in only, zero behavior change); it is a one-line change plus a changelog note. Your call, since it is your semver contract.What changed
AmazonCreatorsApi.__init__takestimeout: float | None = DEFAULT_TIMEOUTand forwards_request_timeout=self.timeoutat all four SDK call sites.AsyncAmazonCreatorsApi.__init__takes the same parameter and passes it to bothAsyncHttpClientconstruction sites (the context-manager client and the per-request one). Async callers were previously stuck with 30 seconds and no way to change it.DEFAULT_TIMEOUTmoves fromaio/client.pytocore/constants.py, next toDEFAULT_THROTTLING, so both layers can share one value. It has to live there rather than inaio/client.py, because that module importshttpxat module scope and httpx is an optional extra — importing it from the sync path would make every sync-only install require httpx. It is still importable fromaio.clientas before, so nothing downstream breaks.AsyncHttpClient'stimeoutannotation widens tofloat | None, sinceNoneis how both httpx and the SDK spell "wait indefinitely".None.Seconds and float throughout, matching
urllib3,httpx, Amazon's_request_timeout, and the existingthrottlingparameter next to it. Ints work fine (timeout=10); the SDK normalizes them.No files under
creatorsapi_python_sdk/were touched. Amazon's SDK already accepts_request_timeouton everyDefaultApimethod — the wrapper simply never set it. This is plumbing, not a design change.The async half is separable. If you would rather keep this to the sync fix, I will drop it and leave
AsyncAmazonCreatorsApias is.Checks
ruff format,ruff check,mypy, and the full test suite pass locally on Python 3.9 through 3.14. Verified in a clean environment without httpx installed that the sync API still imports and picks up the default.CHANGELOG.md,pyproject.toml, anddocs/conf.pyare bumped to 6.4.0 and passscripts/check_version.py.Unrelated to #86 / #76, despite the similar title — that issue was a script not exiting on Windows in the legacy
amazon_paapimodule, not a network timeout.